package com.bustle.commons.http;

import java.io.UnsupportedEncodingException;

import org.apache.http.entity.StringEntity;

import com.bustle.commons.Converter;
import com.google.gson.Gson;

public class TypeToJsonHttpConverter<Type> implements Converter<Type, StringEntity>
{
  public TypeToJsonHttpConverter(Class<Type> aClass)
  {
    type = aClass;
  }

  @Override
  public StringEntity convert(Type aSource)
  {
    try
    {
      Gson gson = new Gson();
      StringEntity stringEntity = new StringEntity(gson.toJson(aSource));
      stringEntity.setContentType("application/xml");

      return stringEntity;
    }
    catch (UnsupportedEncodingException anException)
    {
      anException.printStackTrace();
    }
    return null;
  }

  protected Class<Type> type;
}
